<?php

$m = new Mongo();

$collection = $m->reader->bookshelf;

$cursor = $collection->find();

$name_map = array();

while($cursor->hasNext()) {
    //var_dump($cursor->getNext());

    $arr = $cursor->getNext();
    $id = $arr["_id"];
    $list = $arr["books"];

    if (count($list) <= 1)
        continue;

    foreach( $list as $i)
        $name_map[$i["id"]] = $i["n"];
}

foreach ($name_map as $id => $name)
    echo $id." ".$name."\n";


?>
